package com.letu.core.converter;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;
import java.time.LocalDateTime;
import java.time.ZoneId;


@JsonComponent
public class LocalDateTimeSerializer2 extends JsonSerializer<LocalDateTime> {
    @Override
    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
            throws IOException {
        if (value != null) {
            long timestamp = value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
            gen.writeNumber(timestamp);
        }
    }

//    @Override
//    public void serialize(LocalDateTime value, JsonGenerator gen, SerializerProvider serializers)
//            throws IOException {
//        if (value != null) {
//            long timestamp = value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
//            gen.writeNumber(timestamp);
//        }
//    }
}